package com.sc.core.util;

import com.sc.core.util.translator.Lang;
import com.sc.core.util.translator.TranslatorFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.Map;

@Component
public class Translation {
    private final TranslatorFactory translatorFactory;
    private final String defaultTranslator;

    public Translation(TranslatorFactory translatorFactory, @Value("${translation.default-translator}") String defaultTranslator) {
        this.translatorFactory = translatorFactory;
        this.defaultTranslator = defaultTranslator == null ? "baidu" : defaultTranslator;
    }

    public String translation(String text, Lang source, Lang target) {
        return translatorFactory.getTranslator(defaultTranslator).translation(text, source, target);
    }

    public String translation(String text, Lang target) {
        return translatorFactory.getTranslator(defaultTranslator).translation(text, Lang.AUTO, target);
    }

    public String translation(String text) {
        return translatorFactory.getTranslator(defaultTranslator).translation(text, Lang.AUTO, Lang.EN);
    }
   public Map<String, String> translation(List<String> text, Lang source, Lang target) {
        return translatorFactory.getTranslator(defaultTranslator).translation(text, source, target);
    }

    public Map<String, String> translation(List<String> text, Lang target) {
        return translatorFactory.getTranslator(defaultTranslator).translation(text, Lang.AUTO, target);
    }

    public Map<String, String> translation(List<String> text) {
        return translatorFactory.getTranslator(defaultTranslator).translation(text, Lang.AUTO, Lang.EN);
    }

    public String translation(String text, Lang source, Lang target, String translator) {
        return translatorFactory.getTranslator(translator).translation(text, source, target);
    }

    public Map<String, String> translation(List<String> text, Lang source, Lang target, String translator) {
        return translatorFactory.getTranslator(translator).translation(text, source, target);
    }
}
